<html>
	<head>
		<meta charset="utf-8"/>
	</head>
	<body>
	<?php 
		$daction = $_SESSION['action'];
		include 'operations/connection.php';
		session_start();
		$lang = $_SESSION['lang'];
		$query = mysql_query("select a.Tile,a.Content,e.Fullname,a.Timecreate,a.comment,a.EmployeePerforment,a.Description,
				a.TotalTime,a.TripDate,a.Location,a.IDGroupApprove,a.IDStatus from approvedoc a 
				inner join employee e on a.IDEmployee = e.IDEmployee where a.IDApproveDoc = '$id'");
		while ($row = mysql_fetch_array($query))
		{
			$dtitle = $row[Tile];
			$dcontent = $row[Content];
			$dtime = $row[Timecreate];
			$duser = $row[Fullname];
			$dcomment = $row[comment];
			$dperforment = $row[EmployeePerforment];
			$ddescription = $row[Description];
			$dtotalTime = $row[TotalTime];
			$dtripDate = $row[TripDate];
			$dlocation = $row[Location];
			$didgroupapprover = $row[IDGroupApprove];
			$didemployee = $row[IDEmployee];
			$dstatus = $row[IDStatus];
		}
		
		$queryEmployee = mysql_query("SELECT e.FullName,dl.DepartmentName,e.Position 
				FROM employee e INNER JOIN department_lang dl ON dl.IDDepartment = e.IDDepartment
				WHERE e.IDEmployee = '$didemployee' AND dl.LangID = '$lang'");
		while ($row = mysql_fetch_array($queryEmployee))
		{
			$dnameemployee = $row[FullName];
			$dnamedepartment = $row[DepartmentName];
			$dposition = $row[Position];
		}
	?>
	<div class="main_content">
		<ul class="top_but">
			<li><a  class="back-button"><img src="images/back.png" alt="" /></a><p class="hidden">Back</p></li>
				<?php if($daction=="re_not_approve"){?>
				<li><a href="<?echo approve($didgroupapprover, $id_employee)?>"><img src="images/approval.png" alt="" /></a><p class="hidden">Approve</p></li>
				<li><a href="<?echo reject($didgroupapprover, $id_employee)?>"><img src="images/reject.png" alt="" /></a><p class="hidden">Reject</p></li>
				<?php }?>
				
				<?php
					if($daction == "re_reference_waiting"){
				?>
					<li><a href="<?echo viewReference($didgroupapprover, $id_employee)?>"><img src="images/approval.png" alt="" /></a><p class="hidden">Accept</p></li>
				<?php }?>
		</ul>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr>
				<td class="col_left"><?=$l_approver?></td>
				<td colspan="6">
					<table class="tcontent" cellpadding="5" cellspacing="0">
						<tr>
							<td><?=$l_step?></td>
							<td>
								<?
                    			//Get group approver
                    			$query1 = mysql_query("SELECT st.IDConfigStaticLang,e.Fullname FROM listapprove l
										INNER JOIN employee e ON l.IDEmployee = e.IDEmployee
										INNER JOIN `status` st ON l.IDStatus = st.IDStatus
                    					WHERE CONVERT(l.IDGroupApprove USING utf8) = CONVERT('$didgroupapprover' USING utf8)
                    					ORDER BY l.Order ASC");
                    			while ($row = mysql_fetch_array($query1))
                    			{
                    				$dnameapprover = $row[Fullname];
                    				if ($row[IDConfigStaticLang] == 8){
                    					$dstatus=$l_status_complete;
                    				} else if ($row[IDConfigStaticLang] == 9){
                    					$dstatus=$l_status_pending;
                    				} else if ($row[IDConfigStaticLang] == 10){
                    					$dstatus=$l_status_declined;
                    				} else if ($row[IDConfigStaticLang] == 11){
                    					$dstatus=$l_status_saved;
                    				} else if ($row[IDConfigStaticLang] == 20){
                    					$dstatus=$l_status_reference;
                    				}
                    				
                    			?>
                    			<span style="display: block;">
                    				<?=$dnameapprover?>_<?=$dstatus?>
                    			</span>
                    			<?
                    			}
                    			?>
							</td>
							<td><?=$l_reference?>: <b>
								<?
                    			//Get list references
                    			$query2 = mysql_query("SELECT e.Fullname FROM list_reference l
                    					INNER JOIN employee e ON l.id_employee = e.IDEmployee
                    					WHERE CONVERT(l.id_group USING utf8) = CONVERT('$didgroupapprover' USING utf8)");
                    			while ($row = mysql_fetch_array($query2))
                    			{
                    				$dnamereferences = $row[Fullname];
                    			?>
                    			<b><?=$dnamereferences?>;</b>;
                    			<?
                    			}
                    			?>
								</b>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_reference?></td>
				<td class="col_left" width="15%"><?=$l_department?></td>
				<td><?=$dnamedepartment?></td>
				<td width="12%" class="col_left"><?=$l_position?></td>
				<td width="12%"><?=$duser?></td>
				<td class="col_left"><?=$l_fullname?></td>
				<td><?=$dnameemployee?></td>
			</tr>
			<tr>
				<td width="15%" rowspan="2" class="col_left"><?=$l_project?></td>
				<td width="35%" colspan="2" rowspan="2"><?=$dtitle?>
				</td>
				<td rowspan="2" class="col_left"><?=$l_bussiness_date?></td>
				<td class="col_left"><?=$l_location?></td>
				<td colspan="2"><?=$dlocation?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_partner?></td>
				<td colspan="2"><?=$dperforment?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_created_date?></td>
				<td colspan="6"><?=$dtime?></td>
			</tr>
			<tr>
				<td class="col_left"><?=$l_payment_advance?></td>
				<td colspan="6"><?=$l_amount?>: <?=$dperforment?> <?=$l_unit?>(VNĐ)</td>
			</tr>
			<tr>
				<td colspan="7" style="font-size: 18px"><?=$l_title_table?></td>
			</tr>
		</table>
		<table class="tcontent" cellpadding="5" cellspacing="0">
			<tr class="trtit">
				<td width="15%"><?=Items?>(*)</td>
				<td width="50%"><?=$l_content?></td>
				<td width="15%"><?=$l_currency?></td>
				<td width="15%"><?=$l_remarks?></td>
			</tr>
			<?
			$query2 = mysql_query("select adv.items,adv.content,adv.money,adv.notes 
					from ap_advance adv where document_id = '$id'");
			$dtotalmoney = 0;
			while ($row = mysql_fetch_array($query2))
			{
				$dtotalmoney = $dtotalmoney + $row[money];
				echo "<tr><td>$row[items]</td><td>$row[content]</td><td>$row[money]</td><td>$row[notes]</td></tr>";
			}
			?>
			<tr>
				<td colspan="2"><?=$l_total?></td>
				<td></td>
				<td>0</td>
			</tr>
		</table>
      </div>
	</body>
    <?php mysql_close($connection);?>
</html>